package cn.edu.cug.cs.gtl.docsrv.shp.updater;

import cn.edu.cug.cs.gtl.docsrv.shp.block.ShapeBlock;
import cn.edu.cug.cs.gtl.docsrv.shp.manager.ShpManager;
import cn.edu.cug.cs.gtl.mybatis.mapper.shp.ShpAll;

import java.math.BigDecimal;

public class DefaultBlockUpdater implements BlockUpdater{
    ShpManager manager;

    public DefaultBlockUpdater(ShpManager manager) {
        this.manager = manager;
    }

    /**
     * 将一个ShapeBlock插入数据库
     *
     * @param block 图形块
     * @return 成功返回true, 否则返回false
     */
    @Override
    public boolean insert(ShapeBlock block) {
        return this.manager.insert(block.getShpAll());
    }

    /**
     * 读取本地目录中的所有图形文档，将其插入图形库中
     *
     * @param localDir 本地目录
     * @return 成功返回true, 否则返回false
     */
    @Override
    public boolean insert(String localDir) {
        return this.manager.insert(localDir);
    }

    /**
     * 根据shpInternalId删除文档记录
     *
     * @param block 必须填充shpInternalId
     * @return 成功返回true, 否则返回false
     */
    @Override
    public boolean delete(ShapeBlock block) {
        return this.manager.delete(block.getShpAll());
    }

    /**
     * 根据shpInternalId删除文档记录
     *
     * @param shpInternalId
     * @return 成功返回true, 否则返回false
     */
    @Override
    public boolean delete(BigDecimal shpInternalId) {
        ShpAll shpAll=new ShpAll();
        shpAll.setShpInternalId(shpInternalId);
        return this.manager.delete(shpAll);
    }

    /**
     * 根据shpInternalId更新数据库中的记录
     *
     * @param block 该对象的shpInternalId必须填充
     * @return 更新成功返回true, 否则返回false
     */
    @Override
    public boolean update(ShapeBlock block) {
        return this.manager.update(block.getShpAll());
    }
}
